package com.aidex.system.service.impl;

import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.system.domain.CargoDetail;
import com.aidex.system.domain.vo.CargoDetailApply;
import com.aidex.system.mapper.CargoDetailMapper;
import com.aidex.system.service.CargoDetailService;
import com.aidex.system.service.NlpService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 货品清单Service业务层处理
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-10-06
 */
@Service
@Transactional(readOnly = true)
public class CargoDetailServiceImpl extends BaseServiceImpl<CargoDetailMapper, CargoDetail> implements CargoDetailService
{
    private static final Logger log = LoggerFactory.getLogger(CargoDetailServiceImpl.class);

    @Autowired
    private NlpService nlpService;

    /**
     * 获取单条数据
     * @param cargoDetail 货品清单
     * @return 货品清单
     */
    @Override
    public CargoDetail get(CargoDetail cargoDetail)
    {
        CargoDetail dto = super.get(cargoDetail);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 货品清单id
     * @return 货品清单
     */
    @Override
    public CargoDetail get(String id)
    {
        CargoDetail dto = super.get(id);
        return dto;
    }


    /**
     * 查询货品清单列表
     * @param cargoDetail 货品清单
     * @return 货品清单
     */
    @Override
    public List<CargoDetail> findList(CargoDetail cargoDetail)
    {
        return super.findList(cargoDetail);
    }

    /**
     * 分页查询货品清单列表
     * @param cargoDetail 货品清单
     * @return 货品清单
     */
    @Override
    public PageInfo<CargoDetail> findPage(CargoDetail cargoDetail)
    {
        return super.findPage(cargoDetail);
    }

    /**
     * 保存货品清单
     * @param cargoDetail
     * @return 结果
     */
    @Override
    public boolean save(CargoDetail cargoDetail)
    {
        return super.save(cargoDetail);
    }


    /**
     * 删除货品清单信息
     * @param cargoDetail
     * @return 结果
     */
    @Override
    public boolean remove(CargoDetail cargoDetail)
    {
        return super.remove(cargoDetail);
    }

    /**
     * 批量删除货品清单
     * @param ids 需要删除的货品清单ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteCargoDetailByIds(String[] ids)
    {
        return mapper.deleteCargoDetailByIds(ids);
    }

    @Override
    public CargoDetail getByName(String name) {
        return mapper.getByName(name);
    }

    @Override
    @Transactional(readOnly = false)
    public Boolean apply(CargoDetailApply apply) {
        for (String id : apply.getIds()) {
            CargoDetail detail = this.get(id);
            if (0 != detail.getStatus()) {
                continue;
            }
            detail.setStatus(apply.getStatus());
            mapper.update(detail);
            if (1 == apply.getStatus()) {
                nlpService.addWord(detail.getKeywords());
            }
        }
        return Boolean.TRUE;
    }

}
